import pandas as pd

from app_config import get_engine, get_pro

engine_ts = get_engine()


def write_data(data: pd.DataFrame):
    res = data.to_sql('fina_indicator_vip', engine_ts, index=False, if_exists='append', chunksize=5000)
    print(res)


def get_data(p_period: str):
    df = get_pro().fina_indicator_vip(period=p_period)
    return df


if __name__ == '__main__':
    years: list[str] = ['2018', '2019', '2020', '2021', '2022', '2023', '2024', '2025']
    month_days: list[str] = ['0331', '0630', '0930', '1231']
    periods: list = []
    for year in years:
        for month_day in month_days:
            period: str = year + month_day
            periods.append(period)
            df_income = get_data(period)
            write_data(df_income)
            print(df_income)
    print(periods)
